package com.ruoyi.biz.pojo.vo;

import com.alibaba.fastjson.JSON;
import com.ruoyi.biz.util.RespCode;

/**
 * 响应
 *
 * @author yusheng.liu
 * @since 2025/11/8 10:03
 */
public class R {

    public Boolean getSuccess() {
        return isSuccess;
    }

    public void setSuccess(Boolean success) {
        isSuccess = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    private Boolean isSuccess;

    private Integer code;

    private Object data;

    private String msg;

    public R(Boolean isSuccess, Integer code, Object data, String msg) {
        this.isSuccess = isSuccess;
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public static R success(Object data) {
        return new R(true, RespCode.SUCCESS.getCode(), data, RespCode.SUCCESS.getMsg());
    }

    public static R fail(Object data, RespCode respCode) {
        return new R(false, respCode.getCode(), data, respCode.getMsg());
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
